//
//  WBWelcomView.swift
//  WeiboSwift
//
//  Created by hfwd on 2017/6/1.
//  Copyright © 2017年 hfwd. All rights reserved.
//

import UIKit
import SDWebImage

class WBWelcomView: UIView {

    @IBOutlet weak var iconView: UIImageView!
    
    @IBOutlet weak var tipLabel: UILabel!
    
    @IBOutlet weak var iconBottomConstraint: NSLayoutConstraint!
    
    
    class func welcomeView() -> WBWelcomView {
        let nib = UINib(nibName: "WBWelcomView", bundle: nil)
        
        let v = nib.instantiate(withOwner: nil, options: nil)[0] as! WBWelcomView
        
        v.frame = UIScreen.main.bounds
        
        return v
    }

    override func awakeFromNib() {
        
        guard let urlStr = WBNetworkManager.shared.userAccount.avatar_large,
            let url = URL(string: urlStr)
            
            else {
                
                return
        }
        
        iconView.sd_setImage(with: url, placeholderImage: #imageLiteral(resourceName: "welcom_avatar"))
        
        iconView.layer.masksToBounds = true
    }
    
    override func didMoveToWindow() {
         super.didMoveToWindow()
        
        self.layoutIfNeeded()
        
        iconBottomConstraint.constant = bounds.height - 200
        
        UIView.animate(withDuration: 1.0,
                       delay: 0,
                       usingSpringWithDamping: 0.7,
                       initialSpringVelocity: 0,
                       options: [],
                       animations: {
                        //更新约束
                        self.layoutIfNeeded()
        }) { (_) in
            
            UIView.animate(withDuration: 1.0, animations: {
                
                self.tipLabel.alpha = 1.0
                
            }, completion: { (_) in
                
                self.removeFromSuperview()
            })
        }
    }
    
    
}
